package com.ybchen.thread;

import com.ybchen.content.TraceContextHolder;
import lombok.extern.slf4j.Slf4j;

/**
 * @description:
 * @author: alex
 * @create: 2024-10-20 20:24
 */
@Slf4j
public class TraceRunnable implements Runnable {
    private final Runnable target;

    public TraceRunnable(Runnable target) {
        this.target = target;
    }


    @Override
    public void run() {
        TraceContextHolder.setTraceId();
        try {
            target.run();
        } catch (Exception e) {
            log.error("多线程执行异常：{}", e);
        } finally {
            TraceContextHolder.clear();
        }
    }
}
